<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/31 0031
 * Time: 下午 8:26
 */
namespace app\dlc\common\helpers;

use think\Db;

class HtmlHelper
{

    //根据数据库的过滤规则进行过滤
    static function filter($content,$case_item_id){
//        $data = Db::name('case_item_rule')->where(['case_item_id'=>$case_item_id])->order('sort asc')->column('rule_id');
        $cases_id = Db::name("case_item")->where(["id" => $case_item_id])->value("cases_id");
        $ids = Db::name("cases")->where(['id' => $cases_id])->value("rule_id");
        $ids = explode(",", $ids);
        foreach ($ids as $key => $id) {
            $rule = Db::name('rule')->where(['id'=>$id])->value('rule');
            if ($rule){
                $content =  preg_replace($rule,'',$content);
            }
        }
        return $content;
    }

    static function addA($url,$name){
        return '<a data-url="/dlc/website/_edit" data-loader="App-loader" href="'.$url.'">'.$name.'</a>';
    }


    /**
     * 提取字符串中图片url地址
     * @param type $str
     * @return type
     */
    static function getimgs($str) {
        $reg = '/((http|https):\/\/)+(\w+\.)+(\w+)[\w\/\.\-]*(jpg|gif|png)/';
        $matches = array();
        preg_match_all($reg, $str, $matches);
        foreach ($matches[0] as $value) {
            $data[] = $value;
        }
        return $data;
    }
}
